import relationalStore from '@ohos.data.relationalStore';
import UIAbility from '@ohos.app.ability.UIAbility';
class sqliteDB {
   public rdbStore: relationalStore.RdbStore
  // 初始化任务列表
  initDB(context){
    // rdb配置
    const config = {
      name: 'jiaju.db',
      securityLevel: relationalStore.SecurityLevel.S1 // 安全级别
    }
    // 初始化SQL语句
    const sql1 = `CREATE TABLE deviceInfo (
        uid TEXT PRIMARY KEY ,
        name TEXT,
        on_off BOOLEAN,
        place TEXT
        );`
    const sql2 = `CREATE TABLE userInfo (
        uid TEXT PRIMARY KEY ,
        name TEXT,
        image TEXT,
        passwd TEXT,
        birth TEXT
        );`
    const sql3 = `CREATE TABLE homeInfo (
        hid TEXT PRIMARY KEY ,
        name TEXT,
        );`

    // 获取rdb
    relationalStore.getRdbStore(context, config, (err, rdbStore) => {
      if(err) {
        console.log('testTag', '获取rdbStore失败！')
        return
      }
      console.info("shujuku")
      // 执行sql
      rdbStore.executeSql(sql1)
      rdbStore.executeSql(sql2)
      rdbStore.executeSql(sql3)
      console.log('testTag', '创建表成功！')
      // 保存rdbStore
      this.rdbStore = rdbStore
    })
  }
}

let SqliteDB = new sqliteDB()
export default SqliteDB